package com.orangelife.mobile.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.pay.interfaze.IOrderType;

/**
 * 订单类型弹出框
 *
 * @author Administrator
 */
@Deprecated
public class OrderTypePopupWindow extends PopupWindow implements IOrderType {
    private Context context;
    private LinearLayout llAll, llGoods, llActive;
    private ImageView ivAll, ivGoods, ivActive;
    private TextView tvAll, tvGoods, tvActive;
    private OnClickListener clicker;

    public OrderTypePopupWindow(Context context, OnClickListener clicker) {
        this.context = context;
        this.clicker = clicker;
        initView();
        setListener();
    }

    private void setListener() {
        llAll.setOnClickListener(clicker);
        llGoods.setOnClickListener(clicker);
        llActive.setOnClickListener(clicker);
    }

    private void initView() {
        View contentView = LayoutInflater.from(context).inflate(
                R.layout.popwin_order_type, null);
        setContentView(contentView);
        llAll = (LinearLayout) contentView.findViewById(R.id.ll_aLl);
        llGoods = (LinearLayout) contentView.findViewById(R.id.ll_goods);
        llActive = (LinearLayout) contentView.findViewById(R.id.ll_active);
        ivAll = (ImageView) contentView.findViewById(R.id.iv_all);
        ivGoods = (ImageView) contentView.findViewById(R.id.iv_goods);
        ivActive = (ImageView) contentView.findViewById(R.id.iv_active);
        tvAll = (TextView) contentView.findViewById(R.id.tv_all_type);
        tvGoods = (TextView) contentView.findViewById(R.id.tv_goods);
        tvActive = (TextView) contentView.findViewById(R.id.tv_active);
        /* 设置popupwindow的基本属性 */
        this.setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(R.color.white)));
        this.setWidth(android.view.ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
		/* 设置捕获popupwindow外的点击焦点 */
        this.setOutsideTouchable(true);
    }

    @SuppressLint("NewApi")
    @Override
    public void setCurrentImage(String position) {
        if (position.equals("0")) {
            tvAll.setTextColor(context.getResources().getColor(
                    R.color.TextOrange));
            ivAll.setBackground(context.getResources().getDrawable(
                    R.drawable.icon_all_press));
            ivGoods.setBackground(context.getResources().getDrawable(
                    R.drawable.icon_waimai_normal));
            ivActive.setBackground(context.getResources().getDrawable(
                    R.drawable.icon_life_normal));
        } else if (position.equals("1")) {
            tvGoods.setTextColor(context.getResources().getColor(
                    R.color.TextOrange));
            ivAll.setBackground(context.getResources().getDrawable(
                    R.drawable.icon_all_normal));
            ivGoods.setBackground(context.getResources().getDrawable(
                    R.drawable.icon_waimai_press));
            ivActive.setBackground(context.getResources().getDrawable(
                    R.drawable.icon_life_normal));
        } else {
            tvActive.setTextColor(context.getResources().getColor(
                    R.color.TextOrange));
            ivAll.setBackground(context.getResources().getDrawable(
                    R.drawable.icon_all_normal));
            ivGoods.setBackground(context.getResources().getDrawable(
                    R.drawable.icon_waimai_normal));
            ivActive.setBackground(context.getResources().getDrawable(
                    R.drawable.icon_life_press));
        }
    }

    @Override
    public void dismissPopWindow() {
        this.dismiss();
    }

    @Override
    public void showLocation(View v) {
        this.showAsDropDown(v);
    }

}
